<?php
/**
 * 功能描述：	权限管理
 * @datetime	2022-08-12
 * @version   	v2.3
 * @author   	ZHL
 * @copyrigh  	2022 ZHL 版权所有
 */

class Admin_PowerModel extends Model {

    /**
     * Notes:单表查询总数
     * User: ZhuHaili
     */
    function getListsCount($mouldCode, $whereAdd){
        if(isset($whereAdd['where']) && $whereAdd['where']){
            $where = $whereAdd['where'];
            unset($whereAdd['where']);
        }
        $sql = $whereAdd;
        if(isset($where) && $where){
            $sql['where'] = $where;
        }
        $sql['field'] = 'count(1) counts';
        $sql['table'] = $mouldCode;
        $sql['as'] = 'a';
        $result = $this->conn('mysql')->find($sql);
        return isset($result['counts']) ? $result['counts'] : 0;
    }

    /**
     * Notes:单表查询
     * User: ZhuHaili
     */
    function getListsPage($mouldCode, $whereAdd, $start, $limit, $orderby=''){
        if(isset($whereAdd['where']) && $whereAdd['where']){
            $where = $whereAdd['where'];
            unset($whereAdd['where']);
        }
        $sql = $whereAdd;
        if(isset($where) && $where){
            $sql['where'] = $where;
        }
        $sql['field'] = '*';
        $sql['table'] = $mouldCode;
        $sql['as'] = 'a';
        $sql['order'] = $orderby ? $orderby : 'a.id desc,a.createdate desc';
        $sql['limit']['start'] = $start;
        $sql['limit']['end'] = $limit;
        $r = $this->conn('mysql')->select($sql);
        return $r;
    }

    /**
     * Notes:权限功能分页列表
     * User: ZhuHaili
     */
    function getFunListsPage($mouldCode, $whereAdd, $start, $limit, $orderby=''){
        if(isset($whereAdd['where']) && $whereAdd['where']){
            $where = $whereAdd['where'];
            unset($whereAdd['where']);
        }
        $sql = $whereAdd;
        if(isset($where) && $where){
            $sql['where'] = $where;
        }
        $sql['field'] = 'a.*,b.menuname,c.menuname menuname2';
        $sql['table'] = $mouldCode;
        $sql['as'] = 'a';
        $sql['leftjoin']['sysmenu'][1] = 'b on b.id=a.menu_id';
        $sql['leftjoin']['sysmenu'][2] = 'c on c.setpath=a.menu_id';
        $sql['order'] = $orderby ? $orderby : 'a.id desc,a.createdate desc';
        $sql['limit']['start'] = $start;
        $sql['limit']['end'] = $limit;
        $r = $this->conn('mysql')->select($sql);
        return $r;
    }

    /**
     * Notes: 列表信息分页数据-导出
     * User: ZHL
     * Date: 2020/10/11
     */
    function getListExecl($mouldCode, $whereAdd, $start, $limit, $orderby){
        if(isset($whereAdd['where']) && $whereAdd['where']){
            $where = $whereAdd['where'];
            unset($whereAdd['where']);
        }
        $sql = $whereAdd;
        if(isset($where) && $where){
            $sql['where'] = $where;
        }
        $sql['field'] = "a.*";
        $sql['table'] = $mouldCode;
        $sql['as'] = 'a';
        $sql['order'] = $orderby ? $orderby : 'a.id desc,a.createdate desc';
        if($limit){
            $sql['limit']['start'] = $start;
            $sql['limit']['end'] = $limit;
        }
        return $this->conn('mysql')->select($sql);
    }
}